package org.duncan.Math2D;

/**
 *
 * @author Duncan
 */
public class Rect2D
{
    private Point2D start, end;

    public Rect2D(Point2D start, Point2D end)
    {
        this.start = start;
        this.end = end;
    }

    public Rect2D setStart(Point2D start)
    {
        this.start = start;
        return this;
    }

    public Rect2D setEnd(Point2D end)
    {
        this.end = end;
        return this;
    }

    public Point2D getStart()
    {
        return this.start;
    }

    public Point2D getEnd()
    {
        return this.end;
    }

    public boolean contains(Point2D p)
    {
        return ((p.getX() > Math.min(getStart().getX(), getEnd().getX()))
             && (p.getY() > Math.min(getStart().getY(), getEnd().getY()))
             && (p.getX() < Math.max(getStart().getX(), getEnd().getX()))
             && (p.getY() < Math.max(getStart().getY(), getEnd().getY())));
    }

    public double getWidth() {
        return Math.max(getStart().getX(), getEnd().getX())
              -Math.min(getStart().getX(), getEnd().getX());
    }

    public double getHeight() {
        return Math.max(getStart().getY(), getEnd().getY())
              -Math.min(getStart().getY(), getEnd().getY());
    }
}